﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplicationGDI2
{
    class Class1
    {
        public class Enumer
        {
            Type enumType;

            ComboBox cb;

            public delegate void EnumChanged(Enumer sender, object value);

            public event EnumChanged onChanged;

            public Enumer(Type enumType, Form form)
            {
                this.enumType = enumType;

                cb = new ComboBox();
                cb.DropDownStyle = ComboBoxStyle.DropDownList;
                cb.SelectedValueChanged += new EventHandler(cb_SelectedValueChanged);

                foreach (var item in Enum.GetValues(enumType))
                {
                    cb.Items.Add(item);
                }

                form.Controls.Add(cb);
            }

            public void SetComboBoxPosition(int x, int y)
            {
                cb.Left = x;
                cb.Top = y;
            }

            void cb_SelectedValueChanged(object sender, EventArgs e)
            {
                ComboBox cb = sender as ComboBox;
                if (cb.SelectedItem == null)
                {
                    return;
                }
                object value = Enum.Parse(enumType, cb.SelectedItem.ToString());

                if (onChanged != null)
                {
                    onChanged(this, value);
                }
            }
        }
    }
}
